<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
<style>
#accountInfo .box-header {
	padding: 19px;
}

#statistics .box-title {
	font-size: 16px;
}

#vol p:nth-child(2) {
	font-size: 15px;
}

select {
	color: black;
}

.ui-autocomplete-input {
	width: 100%;
}
</style>
	</ui:define>
	<ui:define name="content">
		<div class='full-center-content-scroll-noheader'>
			<div class="nav-tabs-custom">
				<h:form id="form1">
					<p:growl id="msgs" showDetail="true" />
					<div class="tab-content no-padding">
						<div class="chart tab-pane active" id="stations" style="position: relative">
							<div class="box box-primary box-solid with-border">
								<div class="box-header">
									<h3 class="box-title">选择查询条件</h3>
									<div class="box-tools pull-right">
										<button class="btn btn-default btn-sm" data-widget="collapse">
											<i class="fa fa-minus"></i>
										</button>
									</div>
								</div>
								<div class="box-body">
									<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
										<p:commandButton value="是" type="button"
											styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
										<p:commandButton value="否" type="button"
											styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
									</p:confirmDialog>
									
									<p:outputLabel value="年份:" />
        							<p:autoComplete id="years" dropdown="true" value="#{equipmentCountController.currentYear}" var="item" itemLabel="#{item}年" itemValue="#{item}"
        								completeMethod="#{equipmentCountController.completeYear}" style="width:150px;margin-left:5px" >
        								<p:ajax event="itemSelect" listener="#{equipmentCountController.onYearSelect}" update="countTable title msgs editBtn reCountBtn" />
        							</p:autoComplete>
        							<p:outputLabel value="电压等级:" style="margin-left:10px"/>
        							<p:autoComplete id="voltages" dropdown="true" value="#{equipmentCountController.currentVoltage}"
        								completeMethod="#{equipmentCountController.completeVoltages}" style="width:150px;margin-left:5px;margin-right:10px" >
        								<p:ajax event="itemSelect" listener="#{equipmentCountController.onVoltageSelect}" update="countTable title msgs editBtn" />
        							</p:autoComplete>
        							
        							<p:commandButton id="editBtn" value="编辑" disabled="#{equipmentCountController.current == null}" icon="ui-icon-pencil" update=":form2:editPanel" onclick="PF('editDialog').show()" 
        								rendered="#{s:hasPermission(session,'jcsj_ycsbtj_bj')}" />
        							<p:commandButton value="新增年份" onclick="PF('addYearDialog').show()" icon="ui-icon-plus" actionListener="#{equipmentCountController.getRecentYears}" 
        								rendered="#{s:hasPermission(session,'jcsj_ycsbtj_xznf')}"/>
        							<p:commandButton id="reCountBtn" value="实时统计" disabled="#{!equipmentCountController.showReGener}" actionListener="#{equipmentCountController.reCountEquipmentInfo}" 
        								icon="fa fa-refresh" update="countTable msgs" rendered="#{s:hasPermission(session,'jcsj_ycsbtj_zxtj')}" >
										<p:confirm header="提示" message="重新统计会覆盖当前已存在的数据， 将从cim数据中进行统计。该操作不可回退确定要继续执行吗？" icon="ui-icon-alert" />
        							</p:commandButton>
        							<p:remoteCommand name="rc" update="countTable msgs" actionListener="#{equipmentCountController.reCountEquipmentInfo}" />
        							<p:commandButton value="导出Excel" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" actionListener="#{equipmentCountController.export}" icon="ui-icon-arrowthick-1-s"
									 rendered="#{s:hasPermission(session,'jcsj_ycsbtj_dc')}" >
								        <p:fileDownload value="#{equipmentCountController.file}" />
								    </p:commandButton>
								</div>
							</div>
							<div class="box box-primary box-solid with-border" style="text-align:center">
								<p:outputLabel id="title" value="#{equipmentCountController.getTitle()}" style="margin-top:20px;margin-bottom:20px;font-size:18px"/>
								<p:dataTable var="item" id="countTable" rows="12"  paginator="true" paginatorPosition="bottom" rowKey="#{item.normalStation.id}"
                         			paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                         			rowsPerPageTemplate="15,20,50" value="#{equipmentCountController.countList}" emptyMessage="无纪录"
                         			selection="#{equipmentCountController.current}">
                         			<p:ajax event="rowSelectRadio" listener="#{equipmentCountController.onRowSelect}" update=":form1:editBtn"/>
                         			 <p:columnGroup type="header">
                         			 	<p:row>
							                <p:column rowspan="2" headerText="" style="width:50px"/>
							                <p:column rowspan="2" headerText="单位" />
							                <p:column rowspan="2" headerText="变电站" />
							                <p:column colspan="2" headerText="变压器" />
							                <p:column colspan="2" headerText="交流线" />
							                <p:column rowspan="2" headerText="换流站座数" rendered="#{equipmentCountController.showDetailInfo}"/>
							                <p:column rowspan="2" headerText="换流变台数" rendered="#{equipmentCountController.showDetailInfo}"/>
							                <p:column colspan="2" headerText="直流线" rendered="#{equipmentCountController.showDetailInfo}"/>
							            </p:row>
							            <p:row>
							                <p:column headerText="台数" />
							                <p:column headerText="容量" />
							                <p:column headerText="数量" />
							                <p:column headerText="长度" />
							                <p:column headerText="数量" rendered="#{equipmentCountController.showDetailInfo}"/>
							                <p:column headerText="长度" rendered="#{equipmentCountController.showDetailInfo}"/>
							            </p:row>
                         			 </p:columnGroup>
									<p:column selectionMode="single" style="text-align:center" />
                         			<p:column headerText="单位" style="text-align:center">
                         				<p:outputLabel value="#{item.rank}" />
                         			</p:column>
                         			<p:column headerText="变电站" style="text-align:center">
                         				<p:outputLabel value="#{item.normalStation.count}" />
                         			</p:column>
                         			<p:column headerText="变压器台数" style="text-align:center">
                         				<p:outputLabel value="#{item.normalTrans.count}" />
                         			</p:column>
                         			<p:column headerText="变压器容量" style="text-align:center">
                         				<p:outputLabel value="#{item.normalTrans.capacity}" />
                         			</p:column>
                         			<p:column headerText="交流线条数" style="text-align:center">
                         				<p:outputLabel value="#{item.acLine.count}" />
                         			</p:column>
                         			<p:column headerText="交流线长度" style="text-align:center">
                         				<p:outputLabel value="#{item.acLine.length}" />
                         			</p:column>
                         			<p:column headerText="换流站座数" style="text-align:center" rendered="#{equipmentCountController.showDetailInfo}">
                         				<p:outputLabel value="#{item.convertStation.count}" />
                         			</p:column>
                         			<p:column headerText="换流变压器" style="text-align:center" rendered="#{equipmentCountController.showDetailInfo}">
                         				<p:outputLabel value="#{item.convertTrans.count}" />
                         			</p:column>
                         			<p:column headerText="直流线条数" style="text-align:center" rendered="#{equipmentCountController.showDetailInfo}">
                         				<p:outputLabel value="#{item.dcLine.count}" />
                         			</p:column>
                         			<p:column headerText="直流线长度" style="text-align:center" rendered="#{equipmentCountController.showDetailInfo}"> 
                         				<p:outputLabel value="#{item.dcLine.length}" />
                         			</p:column>
                         			<p:columnGroup type="footer">
							            <p:row style="font-weight:bold">
							                <p:column colspan="2" style="text-align:right;background-color:#3C8DBC;color:#fff" footerText="汇总:" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('normal')} 座" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('transNormal')} 台" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('transNormalCount')} MAV" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('acline')} 条" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('aclineCount')} KM" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('convert')} 座" rendered="#{equipmentCountController.showDetailInfo}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('transConvert')} 台" rendered="#{equipmentCountController.showDetailInfo}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('dcline')} 条" rendered="#{equipmentCountController.showDetailInfo}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{equipmentCountController.getSummary('dclineCount')} KM" rendered="#{equipmentCountController.showDetailInfo}" />
							            </p:row>
							        </p:columnGroup>
                         		</p:dataTable>
							</div>
						</div>
					</div>
				</h:form>
				
				<h:form id="form2">
					<p:dialog id="editDialog" widgetVar="editDialog" modal="true" header="编辑统计参数" width="310" height="450">
							<p:toolbar>
								<f:facet name="left">
									<p:commandButton value="保存" actionListener="#{equipmentCountController.saveEquipmentCouontInfo}" 
										update=":form1:countTable :form1:msgs :form1:editBtn" oncomplete="PF('editDialog').hide()"/>
									<p:commandButton value="取消" onclick="PF('editDialog').hide()"/>
								</f:facet>
							</p:toolbar>
							<p:panelGrid columns="2" id="editPanel">
								<p:outputLabel value="变电站"/>
								<p:inputNumber value="#{equipmentCountController.current.normalStation.count}" minValue="0" decimalPlaces="0"/>
								
								<p:outputLabel value="变压器台数"/>
								<p:inputNumber value="#{equipmentCountController.current.normalTrans.count}" minValue="0" decimalPlaces="0"/>
								
								<p:outputLabel value="变压器容量"/>
								<p:inputNumber value="#{equipmentCountController.current.normalTrans.capacity}" minValue="0" decimalPlaces="1" />
								
								<p:outputLabel value="交流线条数"/>
								<p:inputNumber value="#{equipmentCountController.current.acLine.count}" minValue="0" decimalPlaces="0"/>
								
								<p:outputLabel value="交流线长度"/>
								<p:inputNumber value="#{equipmentCountController.current.acLine.length}" minValue="0" decimalPlaces="1"/>
								
								<p:outputLabel value="换流站座数" rendered="#{equipmentCountController.showDetailInfo}" />
								<p:inputNumber value="#{equipmentCountController.current.convertStation.count}" minValue="0" decimalPlaces="0" rendered="#{equipmentCountController.showDetailInfo}" />
								
								<p:outputLabel value="换流变台数" rendered="#{equipmentCountController.showDetailInfo}" />
								<p:inputNumber value="#{equipmentCountController.current.convertTrans.count}" minValue="0" decimalPlaces="0" rendered="#{equipmentCountController.showDetailInfo}" />
								
								<p:outputLabel value="直流线条数" rendered="#{equipmentCountController.showDetailInfo}"  />
								<p:inputNumber value="#{equipmentCountController.current.dcLine.count}" minValue="0" decimalPlaces="0" rendered="#{equipmentCountController.showDetailInfo}" />
								
								<p:outputLabel value="直流线长度" rendered="#{equipmentCountController.showDetailInfo}" />
								<p:inputNumber value="#{equipmentCountController.current.dcLine.length}" minValue="0" decimalPlaces="2" rendered="#{equipmentCountController.showDetailInfo}" />
							</p:panelGrid>
					</p:dialog>
				</h:form>
				
				<h:form id="form3">
					<p:dialog id="addYearDialog" widgetVar="addYearDialog" modal="true" header="添加统计年份" width="250" height="250">
							<p:toolbar>
								<f:facet name="left">
									<p:commandButton value="确定" icon="ui-icon-check" update=":form4:sourceList :form1:msgs" actionListener="#{equipmentCountController.openSourceDialog}"/>
									<p:commandButton value="取消" icon="ui-icon-close" onclick="PF('addYearDialog').hide()"/>
								</f:facet>
							</p:toolbar>
							<p:outputLabel value="选择要添加的年份:" style="margin-top:10px"/>
							<p:autoComplete dropdown="true" value="#{equipmentCountController.newYear}" completeMethod="#{equipmentCountController.getRecentYears()}" style="width:99%" />
					</p:dialog>
				</h:form>
				<h:form id="form4">
					<p:dialog id="importDialog" widgetVar="importDialog" modal="true" header="选择数据源" width="250" height="250">
						<p:toolbar>
							<f:facet name="left">
								<p:commandButton value="保存" update=":form1:msgs :form1:countTable :form1:years :form1:voltages :form1:title" icon="ui-icon-disk" oncomplete="PF('importDialog').hide()" actionListener="#{equipmentCountController.copyCountInfo}"/>
								<p:commandButton value="取消" icon="ui-icon-close" onclick="PF('importDialog').hide()" actionListener="#{equipmentCountController.hideAddYearDialog}"/>
							</f:facet>
						</p:toolbar>
						<p:outputLabel value="将已存在的数据导入到该年份中:" style="margin-top:10px"/>
						 <p:selectOneListbox id="sourceList" value="#{equipmentCountController.sourceYear}" style="width:100%">
            				<f:selectItems value="#{equipmentCountController.sourceYears}" var="year" itemLabel="#{year}年" itemValue="#{year}" />
					     </p:selectOneListbox>
					</p:dialog>
				</h:form>
			</div>
		</div>

	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/plugins/datatables/jquery.dataTables.js"></script>
		<script src="/resources/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="/resources/js/tables/mytable.js"></script>
		<script src="/resources/js/mymodal.js"></script>
		<script src="/resources/plugins/snapsvg/snap.svg.js"></script>
		<script>
		</script>
	</ui:define>
</ui:composition>
